package cn.edu.cdu.taobao.util;

import java.io.IOException;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import cn.edu.cdu.taobao.bean.Item;

public class ShopItemInfo {
	Item item;
	//Netutil netutil;
	PageInfo pageInfo;

	public ShopItemInfo(String url) {
		//netutil = new Netutil(url);
		pageInfo=new PageInfo(url);
		item = new Item();
		item.setShopInfo(pageInfo.getShopInfo());
		item.setItemInfo(pageInfo.getItemInfo());
		
		System.out.println(pageInfo.getPriceURL());
		System.out.println(pageInfo.getCommnetURL());
		System.out.println(pageInfo.getTradeURL());
		
		item.setItemPrice(getPrice());
		item.setItemComment(getComment());
		item.setItemTrade(getTrade());
		
		
	}

	/**
	 * 
	 * @return
	 */
	public String getPrice() {
		Document doc = null;
		try {
			doc = Jsoup.connect(pageInfo.getPriceURL()).referrer("").get();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doc.toString();

	}

	public String getComment() {
		Document doc = null;
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		try {
			doc = Jsoup.connect(pageInfo.getCommnetURL()).referrer("")
					.header("User-Agent",
							"Mozilla/5.0 (Windows NT 6.1; rv:16.0) Gecko/20100101 Firefox/16.0")
					.header("Accept-Language",
							"zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3")
					.header("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
					.get();		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return doc.toString();

	}

	public String getTrade() {
		
		return HttpBrowser.getUrl(pageInfo.getTradeURL());
	}

	public String getShopInfo() {
		// TODO Auto-generated method stub
		return item.getShopInfo();
	}

	public String getItemInfo() {
		// TODO Auto-generated method stub
		return item.getItemInfo();
	}

}
